package com.udata.server.util;

import java.security.MessageDigest;

import org.apache.commons.codec.binary.Base64;

import com.udata.shared.exception.OperationException;

public class EncodeUtil {

  public static String encodePassword(String password) throws OperationException {
    try {
      MessageDigest md = MessageDigest.getInstance("SHA-256");
      byte[] passwordArray = md.digest(password.getBytes());

      password = new String(Base64.encodeBase64(passwordArray));
      return password;

    } catch (Exception e) {
      throw new OperationException(EncodeUtil.class.getCanonicalName() + ".encodePassword\n"
          + e.getMessage());
    }
  }
}
